﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace ShenLan.Common
{
    /// <summary>
    /// 自动任务
    /// </summary>
    public class AutoTask
    {

        public AutoTask() { }

        /// <summary>
        /// 执行所有设定的自动任务
        /// </summary>
        public static void ExeAutoTask()
        {
            //1000=1秒钟，60000=1分钟，定每隔多长时间执行任务
            //
            var sendEmailTask = new System.Timers.Timer();

            //10分钟执行一次           
            sendEmailTask.Interval = 600000; //引发System.Timers.Timer.Elapsed,即AutoSendEmail事件的时间间隔,以毫秒为单位
            sendEmailTask.Elapsed += new System.Timers.ElapsedEventHandler(AutoSendEmail);
            sendEmailTask.Start();

            var second = new System.Timers.Timer(600000);//10分钟执行一次
            second.Elapsed += new System.Timers.ElapsedEventHandler(AutoSendSMS);
            second.Start();
        }

        /// <summary>
        /// 定时发送邮件任务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void AutoSendEmail(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {

            }
            catch (Exception ex)
            {
                WriteFile.WriteErrorToTxt(ex);
            }
        }

        /// <summary>
        ///自动发送短信任务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void AutoSendSMS(object sender, System.Timers.ElapsedEventArgs e)
        {

        }
    }
}